-- UIActivityDungeon
-- Created by chengb May/4/2016
-- 活动副本界面

require "game/ui/form/shop/UIPetRecruit"
require "game/ui/form/dungeon/UIEnterDungeon"
require "game/ui/form/combat_stat/UIMopUp"
require "game/ui/form/main/UIMopUpEffect"
require "game/ui/form/market/UIScrapMarket"
require "game/ui/form/activity/UIActivityExchange"

UIActivityDungeon = class("UIActivityDungeon", function()
    return cc.Layer:create();
end);

function UIActivityDungeon.create(id)
    return UIActivityDungeon.new(id);
end

-- 构造函数
function UIActivityDungeon:ctor(id)
    self:setName("UIActivityDungeon");
    self.id = id;
    self.areaId = ActivityDungeonM.getMainDungeonById(id);

    -- 这边初始化一下当前经验值，在扫荡时候会用到
    self.exp = ME.user:getExp();
    self.level = ME.user:getLevel();

    -- 初始化
    local node = cc.CSLoader:createNode("layout/main/SubMapList.csb");
    self:addChild(node);
    self.node = node;
    local scrollview = findChildByName(self.node, "TOP/scrollview");
    self.scrollview = scrollview;

    -- 适配
    self:resize();

    -- 注册点击事件
    self:registerTouchEvent();

    -- 注册事件处理回调函数
    self:regiserEventCallback();

    -- 初始化窗口
    self:initForm();

    -- 显示扫荡次数
    self:updateMopupTimes();

    -- 检查按钮
    self:checkBtn();

    -- 初始化标示
    self.isInit = true;
end

-- 注册事件处理回调函数
function UIActivityDungeon:regiserEventCallback()
    -- 关注扫荡成功的回调
    EventMgr.register("UIActivityDungeon", event.MOP_UP_DONE, function(args)
        -- 提示扫荡成功
        self:whenMopUpDone(args);
    end);

    -- 关注激活宠物事件
    EventMgr.register("UIActivityDungeon", event.GAIN_PET, function()
        -- 检查按钮
        self:checkBtn();
    end);

    -- 注册获得焦点的回调
    EventMgr.register("UIActivityDungeon", event.FOCUS_CHANGED, function(para)
        if para["get"] == "UIActivityDungeon" then
            UIMgr:getCurrentScene().topMenu:show(TOPMENU_FRAME_TREE, TOPMENU_FRAME_LIFE);
        end

        if para["get"] == "UIInvisibleForm" or para["lose"] == "UIInvisibleForm" then
            return;
        end

        -- 非初始化获得焦点，BOTTOM向上
        if para["get"] == "UIActivityDungeon" then
            if not self.isInit then
                self:bottomFlyUp();
            end
        elseif para["lose"] == "UIActivityDungeon" then
            -- 失去焦点BOTTOM隐藏
            self:showBottomBotton(false);
        end

        if self.isInit then
            self.isInit = false;
        end
    end);

    -- 关注碎片变化
    local petId = ActivityDungeonM.query(self.id, nil, "pet_id");
    local scrapId = PetM.query(petId, "chips");
    EventMgr.register("UIActivityDungeon", event.ITEM_COUNT_UPDATED, function(classId)
        if classId == scrapId then
            self:checkBtn();
        end
    end);

    -- 关注活动结束
    EventMgr.register("UIActivityDungeon", event.ACTIVITY_CLOSE, function(args)
        local id = args["id"];
        if id ~= self.id then
            return;
        end

        -- 关闭界面
        UIMgr.getCurrentScene():removeFormByName("UIActivityDungeon");
        UIMgr.getCurrentScene():removeFormByName("UIPetRecruit");
        UIMgr.getCurrentScene():removeFormByName("UIScrapMarket");
    end);

    self:registerScriptHandler(function(ev)
        if ev == "exit" then
            cclog("UIActivityDungeon 界面析构清理");
            EventMgr.removeAll("UIActivityDungeon");
        end
    end);
end

-- 注册点击事件
function UIActivityDungeon:registerTouchEvent()
    local TOP = findChildByName(self.node, "TOP");
    local BT = findChildByName(self.node, "BT");

    -- 注册返回按钮点击事件
    local btnBack = findChildByName(BT, "btn_back");
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_return");
            closeFormByName("UIActivityDungeon");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);

    -- 注册招募按钮点击事件
    local btnRecruit = findChildByName(BT, "btn_dungeon");
    TextStyleM.setTextStyle(btnRecruit, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnRecruit:setTitleText(getLocStr("btn_text_recruit2"));
    local function onRecruitClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_click");
            local petId = ActivityDungeonM.query(self.id, nil, "pet_id");

            -- 如果在活动兑换表里面配置了兑换商品
            if #ActivityM.getActivityExchangeList(self.id) > 0 then
                UIMgr.getCurrentScene():removeFormByName("UIActivityExchange");
                local uiForm = UIActivityExchange.create(self.id);
                UIMgr.getCurrentScene():addForm(uiForm);
            elseif PetM.getMyPet(petId) then
                -- 打开碎片商店界面
                UIMgr.getCurrentScene():removeFormByName("UIScrapMarket");
                local uiScrap = UIScrapMarket.create("ActivityShop");
                UIMgr.getCurrentScene():addForm(uiScrap);
            else
                -- 打开招募界面
                local campId = ActivityDungeonM.query(self.id, nil, "camp_id");
                UIMgr.getCurrentScene():removeFormByName("UIPetRecruit");
                local uiPetRecruit = UIPetRecruit.create(campId, { petId });
                UIMgr.getCurrentScene():addForm(uiPetRecruit);
            end
        end
    end
    btnRecruit:addTouchEventListener(onRecruitClick);
end

-- 检查按钮
function UIActivityDungeon:checkBtn()
    local petId = ActivityDungeonM.query(self.id, nil, "pet_id");
    local btnRecruit = findChildByName(self.node, "BT/btn_dungeon");

    -- 如果在活动兑换表里面配置了兑换商品
    if #ActivityM.getActivityExchangeList(self.id) > 0 then
        local title = ActivityM.query(self.id, "exchange_title");
        btnRecruit:setTitleText(title);
    elseif PetM.getMyPet(petId) then
        -- 显示碎片商店
        btnRecruit:setTitleText(getLocStr("btn_text_activity_shop"));
    else
        -- 显示招募
        btnRecruit:setTitleText(getLocStr("btn_text_recruit2"));
    end

    -- 如果有可招募的冈布奥，需要显示气泡
    local hintImg = findChildByName(btnRecruit, "hint");
    local petId = ActivityDungeonM.query(self.id, nil, "pet_id");
    if PetShopM.canHirePet(petId) then
        hintImg:setVisible(true);
        checkBlueBubbleStatus(hintImg, true);
    else
        hintImg:setVisible(false);
    end
end

-- 初始化窗口
function UIActivityDungeon:initForm()
    local BT = findChildByName(self.node, "BT");

    -- 设置标题
    local TOP = findChildByName(self.node, "TOP");
    local titleLabel = findChildByName(TOP, "title_bg/text");
    TextStyleM.setOutlineStyle(titleLabel, 1, TextStyleM.TEXT_OUTLINE_COLOR, true);
    local activityName = ActivityDungeonM.query(self.id, nil, "name");
    titleLabel:setString(activityName);
    TextStyleM.setArtWordTitleStyle(titleLabel);

    -- 显示活动剩余时间
    local remainTimeLabel = findChildByName(TOP, "title_bg/remain_time");
    remainTimeLabel:setVisible(true);
    self.remainTimeLabel = remainTimeLabel;
    local remainTime = ActivityM.getRemainTime(self.id);
    self:updateRemainTime(remainTime);

    local info = ActivityM.getActivityInfo(self.id);
    if ActivityM.getActivityStatus(info) == ACTIVITY_STATUS_END then
        -- 结束了
        self:showEndTip();
    else
        -- 显示副本列表
        self:showDungeonList();
    end

    -- 隐藏不相关的按钮
    local btnLeaderboard = findChildByName(self.node, "BT/leaderboard");
    btnLeaderboard:setVisible(false);
end

-- 显示副本列表
function UIActivityDungeon:showDungeonList()
    local scrollview = self.scrollview;
    scrollview:removeAllChildren();
    local itemNode = cc.CSLoader:createNode("layout/main/SubMapItem.csb");
    local widget = replaceNodeWithWidget(itemNode);

    local activities = ActivityDungeonM.getActivitiesById(self.id);

    -- 左边距
    local leftMargin = 306;

    -- 行间距
    local gap = 15;
    local widgetHeight = 107;

    -- 活动个数
    local totalNum = #activities;

    if ActivityDungeonM.isGradePassById(self.id, 3)
        and MopUpM.isMopUpActive() then
        -- 可以扫荡
        totalNum = totalNum + 1;
    end

    local startHeight = 108 / 2;

    -- 计算总高度
    local totalHeight = totalNum * (widgetHeight + gap);
    if totalHeight < self.originScrollviewHeight then
        startHeight = self.originScrollviewHeight - totalHeight + 108 / 2;
    end

    scrollview:setInnerContainerSize(cc.size(scrollview:getInnerContainerSize().width,
        math.max(totalHeight, self.originScrollviewHeight)));

    local i = 0;
    self.items = {};
    if ActivityDungeonM.isGradePassById(self.id, 3) and
        MopUpM.isMopUpActive() then
        -- 所有小关都已通关
        -- 暂离状态(SLIMEC_3367暂离状态也可以扫荡)
        -- 扫荡功能已经激活
        local child = widget:clone();
        local x = leftMargin;
        local y = startHeight + i * (widgetHeight + gap);
        child:setPositionX(x);
        child:setPositionY(y);
        child:setName("mopupItem");

        table.insert(self.items, child);

        -- 初始化奖励
        child:setTag(i);
        self:initMopUpItem(child);
        scrollview:addChild(child);
        i = i + 1;
    end

    for _, info in pairs(activities) do
        local child = widget:clone();
        local x = leftMargin;
        local y = startHeight + i * (widgetHeight + gap);
        child:setPositionX(x);
        child:setPositionY(y);

        table.insert(self.items, child);

        -- 初始化奖励
        self:initSubItem(child, info);

        scrollview:addChild(child);
        i = i + 1;
    end

    -- 默认滑到最顶端
    scrollview:scrollToTop(0.1, true);

    -- 播放飞入效果
    local list = {};
    for i = #self.items, 1, -1 do
        table.insert(list, self.items[i]);
    end

    commonScrollItemFlyIn(list);
end

-- 显示活动剩余时间
function UIActivityDungeon:updateRemainTime(remainTime)
    local timeDesc = remainingTimeDesc2(remainTime);
    local remainTimeLabel = self.remainTimeLabel;
    TextStyleM.setOutlineStyle(remainTimeLabel, TextStyleM.TEXT_OUTLINE_SIZE, TextStyleM.TEXT_OUTLINE_COLOR_DARK);
    TextStyleM.setTextStyle(remainTimeLabel, TextStyleM.TEXT_SIZE_MINI, TextStyleM.TEXT_COLOR_LIGHT_YELLOW);
    self.remainTimeLabel = applyString(remainTimeLabel, timeDesc);

    -- 如果还有剩余，每秒刷新一次
    if remainTime > 0 then
        local function callback()
            self:updateRemainTime(remainTime - 1);
        end
        performWithDelay(self.node, callback, 1.0);
    else
        -- 活动结束了，关掉页面
        local info = ActivityM.getActivityInfo(self.id);
        if ActivityM.getActivityStatus(info) == ACTIVITY_STATUS_CLOSE then
            UIMgr.getCurrentScene():removeFormByName("UIActivityDungeon");
        else
            self.remainTimeLabel:setVisible(false);
            self.scrollview:setVisible(false);
            self:showEndTip();
        end
    end
end

-- 显示结束提示
function UIActivityDungeon:showEndTip()
    local emptyDesc = findChildByName(self.node, "TOP/empty_desc");
    emptyDesc:setVisible(true);
    emptyDesc:setAnchorPoint(0.5, 0);
    emptyDesc:getVirtualRenderer():setHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER);

    local name = "";
    local item = (ActivityM.query(self.id, "activity_items") or {})[1];
    if item then
        name = ItemM.query(item, "name");
    end

    -- 绘制剩余兑换时间
    local function tick()
        local remainTime = ActivityM.getRemainRunningTime(self.id);
        local timeDesc = remainingTimeDesc(remainTime);
        TextStyleM.setTextStyle(emptyDesc, TextStyleM.TEXT_SIZE_MIDDLE2, TextStyleM.TEXT_COLOR_ORANGE, true);
        emptyDesc:setString(string.format(getLocStr("normal_activity_end_tip"), timeDesc, name, name));

        performWithDelay(self, tick, 1);
    end

    tick();
end

-- 初始化二级页面项
function UIActivityDungeon:initSubItem(child, info)
    child.info = info;

    -- 难度名称
    local grade = info["grade"];
    local gradeName = ""
    if grade == ACTIVITY_GRADE_EASY then
        gradeName = getLocStr("activity_grade_easy");
    elseif grade == ACTIVITY_GRADE_NORMAL then
        gradeName = getLocStr("activity_grade_normal");
    else
        gradeName = getLocStr("activity_grade_difficult");
    end
    local nameLabel = findChildByName(child, "name");
    TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_LIGHT_YELLOW, true, -3, 1.2, nil, nil, nil, true);
    nameLabel:setString(gradeName);

    -- 关卡背景图片
    local dungeonId = info["dungeon_id"];
    local areaImg = findChildByName(child, "area_bg");
    local areaIcon = DungeonAreaM.query(dungeonId, "area_bg");
    areaImg:loadTexture(getSubAreaBgPath(areaIcon));

    -- 难度
    local layerLabel = findChildByName(child, "layer");
    local maxFloor = DungeonAreaM.query(dungeonId, "max_floor");
    TextStyleM.setTextStyle(layerLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_LIGHT_BLUE, true, -2, 1.2, nil, nil, nil, true);
    if grade == ACTIVITY_GRADE_DIFFICULT and info["tip"] and #info["tip"] > 0 then
        -- 困难模式限制提示
        layerLabel:setString(string.format(getLocStr("sub_area_layer2"), maxFloor));
    else
        layerLabel:setString(string.format(getLocStr("sub_area_layer3"), maxFloor));
    end

    -- TODO 钻石奖励图标
    local diamondImage = findChildByName(child, "diamond_bg");
    diamondImage:setVisible(false);
    local diamondNumLabel = findChildByName(child, "num");
    diamondNumLabel:setVisible(false);
    local lightImage = findChildByName(child, "light");
    lightImage:setVisible(false);

    -- 显示体力消耗
    local lifeNode = findChildByName(child, "life_icon");
    local requireLife = DungeonAreaM.calcDungeonLifeCost(dungeonId);
    local layer = createLifeLayer(requireLife, "right", -0.4);
    lifeNode:removeAllChildren();
    lifeNode:addChild(layer);

    local statusLabel = findChildByName(child, "status");
    if getLang() ~= "zh" and getLang() ~= "tw" then
        statusLabel = findChildByName(child, "status_en");
    end
    TextStyleM.setOutlineStyle(statusLabel, TextStyleM.TEXT_OUTLINE_SIZE, TextStyleM.TEXT_OUTLINE_COLOR_DARK);
    TextStyleM.setTextStyle(statusLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_LIGHT_BLUE, true, -2, 1.2);
    statusLabel:setVisible(false);

    -- 是否领取通关奖励
    if DungeonAreaM.isDungeonPassed(ME.user, dungeonId) and
        not DungeonAreaM.isDungeonPassBonusTaken(ME.user, dungeonId) then
        statusLabel:setVisible(false);
        lifeNode:setVisible(false);

        local rotateForever = cc.RepeatForever:create(cc.RotateBy:create(30, 360));
        lightImage:runAction(rotateForever);
        lightImage:setVisible(true);

        if DungeonAreaM.isLifeBonusArea(dungeonId) then
            diamondImage:loadTexture("images/ui/main/bag_of_gem_and_life.png");
        else
            diamondImage:setVisible(true);
        end
        playBubbleAnima2(diamondImage, false, 1);
    end

    -- 背景图片水平翻转
    local bg = findChildByName(child, "bg");
    bg:setFlippedX(true);

    -- 背景色/是否可以点击
    local btnBg = findChildByName(child, "btn_bg");

    -- 可以重复打/故不受限制
    btnBg:setTouchEnabled(true);
    setGrayMode(btnBg, false);
    setGrayMode(areaImg, false);

    -- 注册按钮点击事件
    AddTouchEventListener(btnBg, function (sender, eventType)
        if eventType == ccui.TouchEventType.began then
            -- 1.变小
            local downTime  = 0.25/2;
            local scaleDown = cc.ScaleTo:create(downTime, 0.95);
            child:runAction(scaleDown);
        elseif eventType == ccui.TouchEventType.ended then
            -- 2.变大
            local downTime  = 0.25/2;
            local scaleUp = cc.ScaleTo:create(downTime, 1);
            child:runAction(scaleUp);
        elseif eventType == ccui.TouchEventType.canceled then
            -- 3.变大
            local downTime  = 0.25/2;
            local scaleUp = cc.ScaleTo:create(downTime, 1);
            child:runAction(scaleUp);
        end

        if eventType == ccui.TouchEventType.ended then
            if DungeonM.isPause() then
                -- 暂离状态(提示状态)
                alert(getLocStr("cant_restart_dungeon"));
                return;
            end

            if ActivityM.getRemainTime(info.id) <= 0 then
                -- 活动已结束
                alert(getLocStr("activity_is_over"));
                return;
            end

            if DungeonAreaM.isDungeonPassed(ME.user, dungeonId) and
                not DungeonAreaM.isDungeonPassBonusTaken(ME.user, dungeonId) then
                -- 已经通关了
                if DungeonAreaM.canTakeDungeonPassBonus(id) == "life_full" then
                    alert(getLocStr("cannot_take_life_bonus"));
                    return;
                end
                Operation.cmd_take_dungeon_pass_bonus(dungeonId);
                self:showDungeonList();
                self:updateMopupTimes();
                return;
            end

            -- 如果体力不足，弹出购买提示
            local requireLife = DungeonAreaM.calcDungeonLifeCost(dungeonId);
            if ME.user.dbase:query("life", 0) < requireLife then
                confirmBuyLife();
                return;
            end

            -- 打开关卡进入界面
            UIMgr:getCurrentScene():removeFormByName("UIEnterDungeon");
            local uiEnterDungeon = UIEnterDungeon.create(dungeonId);
            UIMgr.getCurrentScene():addForm(uiEnterDungeon);
            AudioM.playFx("ui_open1");
        end
    end);
end

-- 扫荡项目
function UIActivityDungeon:initMopUpItem(node)
    -- 名称
    local nameLabel = findChildByName(node, "name");

    -- 关卡背景图片
    local areaBg = findChildByName(node, "area_bg");
    local bgIndex = DungeonAreaM.query(self.areaId, "area_bg");
    areaBg:loadTexture(getSubAreaBgPath(bgIndex));

    -- 次数
    local layerLabel = findChildByName(node, "layer");
    local remainTimes = MopUpM.getRemainMopUpTimes(self.areaId);
    local maxTimes = MopUpM.getMaxMopUpTimes(self.areaId);

    TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_LIGHT_GREEN, true, -3, 1.2, nil, nil, nil, true);
    TextStyleM.setTextStyle(layerLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_LIGHT_BLUE, true, -2, 1.2, nil, nil, nil, true);

    layerLabel:setString(string.format(getLocStr("remainder_times"), remainTimes));
    nameLabel:setString(getLocStr("mopup_text"));

    local lifeIcon = findChildByName(node, "life_icon");
    local statusLabel = findChildByName(node, "status");
    if getLang() ~= "zh" and getLang() ~= "tw" then
        statusLabel = findChildByName(node, "status_en");
    end
    local lifeCost = DungeonAreaM.query(self.areaId, "mop_up_life");
    local lifeLayer = createLifeLayer(lifeCost, "right", -0.4);
    statusLabel:setVisible(false);
    lifeIcon:addChild(lifeLayer);
    lifeIcon:setVisible(true);

    statusLabel:setVisible(false);

    local diamondImage = findChildByName(node, "diamond_bg");
    diamondImage:setVisible(false);
    local diamondNumLabel = findChildByName(node, "num");
    diamondNumLabel:setVisible(false);
    local lightImage = findChildByName(node, "light");
    lightImage:setVisible(false);

    --注册回调信息
    local bgBtn = findChildByName(node, "btn_bg");
    AddTouchEventListener(bgBtn, function (sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_click");

            if ActivityM.getRemainTime(self.id) <= 0 then
                -- 活动已结束
                alert(getLocStr("activity_is_over"));
                return;
            end

            -- 获得扫荡前的经验
            self.exp = ME.user:getExp();
            self.level = ME.user:getLevel();

            cclog("扫荡之前的的经验："..ME.user:getExp());
            self:tryMopUp();
        end
    end);
end

-- 尝试扫荡
function UIActivityDungeon:tryMopUp()
    -- 判断能否扫荡
    local ret = MopUpM.canMopUp(self.areaId);
    if true ~= ret then
        trace("UISubAreaList", "扫荡失败，原因：" .. tostring(ret));

        if ret == "life_lack" then
            -- 失败原因是体力不足，弹出购买体力确认提示
            confirmBuyLife();
        end

        return;
    end

    local requireLife = DungeonAreaM.query(self.areaId, "mop_up_life");

    -- 请求扫荡
    local function sendCmd()
        Operation.cmd_mop_up(self.areaId);
    end
    performWithDelay(self, sendCmd, 1.3);

    local uiForm = UIMopUpEffect.create();
    UIMgr.getCurrentScene():addForm(uiForm);

    playLifeConsumeEffect(requireLife);
end

-- 扫荡成功的回调
function UIActivityDungeon:whenMopUpDone(args)
    local bonus = args["bonus"];

    -- 重绘扫荡按钮
    self:updateMopupTimes();

    UIMgr.getCurrentScene():removeFormByName("UIMopUp");
    local uiMopUp = UIMopUp.create(args, self.exp, self.level, self.areaId);

    UIMgr.getCurrentScene():removeFormByName("UIMopUpEffect");
    UIMgr.getCurrentScene():addForm(uiMopUp);
end

-- 显示扫荡次数
function UIActivityDungeon:updateMopupTimes()
    -- 次数
    local scrollview = findChildByName(self.node, "TOP/scrollview");
    local mopUpItem = findChildByName(scrollview, "mopupItem");
    if mopUpItem ~= nil then
        local timesLabel = findChildByName(mopUpItem, "layer");
        local bgBtn = findChildByName(mopUpItem, "btn_bg");
        local areaBg = findChildByName(mopUpItem, "area_bg");
        -- 如果符合扫荡条件
        local ret = MopUpM.canMopUp(self.areaId);
        if true == ret or "life_lack" == ret then
            -- 扫荡功能可用，或仅活力不足
            -- 按钮可点击
            bgBtn:setTouchEnabled(true);
            setGrayMode(bgBtn, false);
            setGrayMode(areaBg, false);
        else
            -- 按钮不可点击
            bgBtn:setTouchEnabled(false);
            setGrayMode(bgBtn, true);
            setGrayMode(areaBg, true);
        end
        local remainTimes = MopUpM.getRemainMopUpTimes(self.areaId);
        local maxTimes = MopUpM.getMaxMopUpTimes(self.areaId);

        TextStyleM.setTextStyle(timesLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_LIGHT_BLUE, true, -2, 1.2, nil, nil, nil, true);

        timesLabel:setString(string.format(getLocStr("remainder_times"), remainTimes));
    end
end

-- 显示/隐藏底部BUTTON
function UIActivityDungeon:showBottomBotton(visible)
    local BT = findChildByName(self.node, "BT");
    BT:setVisible(visible);
end

-- 获得焦点隐藏焦点
function UIActivityDungeon:bottomFlyUp()
    local bottom = findChildByName(self.node, "BT");
    if bottom then
        bottom:setVisible(true);
        FormEffectM.btPopUpFromBottom(self);
    end
end

-- 适配
function UIActivityDungeon:resize()
    local w = AlignM.frameSize.width;
    local h = AlignM.frameSize.height;

    local scale = w / DESIGN_WIDTH;

    -- 设置scroll的新视口高度
    local scrollview = findChildByName(self.node, "TOP/scrollview");
    local scrollViewSize = scrollview:getContentSize();

    local height = (h / scale) - 420;
    scrollview:setContentSize(scrollViewSize.width, height);

    -- 保存窗口适配后的原始高度
    self.originScrollviewHeight = height;

    local node = self.node;

    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");
    AlignM.fitToScreen(node, "bg2");

    -- TOP置于顶部中间并缩放至合适大小
    AlignM.alignToTopCenter(node, "TOP");

    -- BT置于底部并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end



